import fractions

def all_perms(str):
	if len(str) <= 1:
		yield str
	else:
		for perm in all_perms(str[1:]):
			for i in range(len(perm)+1):
				yield perm[:i] + str[0:1] + perm[i:]

def consecutive(list):
	gcds = []

	gcd = list[0]
	for i in list:
		gcd = fractions.gcd(gcd, i)
	
	count = 0.0
	for i in list:
		count += 1
		if float(i) / float(gcd) != count:
			return False
	return True

list = []

prange = []
for i in range(0, 10):
	prange.append(str(i))

for perm in all_perms(prange):
	if int("".join(perm[1:4])) % 2 == 0 and \
		int("".join(perm[2:5])) % 3 == 0 and \
		int("".join(perm[3:6])) % 5 == 0 and \
		int("".join(perm[4:7])) % 7 == 0 and \
		int("".join(perm[5:8])) % 11 == 0 and \
		int("".join(perm[6:9])) % 13 == 0 and \
		int("".join(perm[7:10])) % 17 == 0:
			list.append(int("".join(perm)))

print sum(list)
